<?php
/* @var $this ShiftChangeController */
/* @var $model ShiftChange */

$this->breadcrumbs=array(
    'Management'=>array('site/management'),
    'Reporting'=>array('site/reporting'),
    'Shift Change and Q-Shift Swap',
);

$this->menu=array(
    //array('label'=>'Create ShiftChange', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
    $('.search-form').toggle();
    return false;
});
$('.search-form form').submit(function(){
    $('#shift-change-grid').yiiGridView('update', {
        data: $(this).serialize()
    });
    return false;
});
");
?>

<h1>Shift Change and Q-Shift Swap Reporting</h1>

<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>

<br>
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
    'model'=>$model,
)); ?>
</div><!-- search-form -->

<?php 

$gridWidget = $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'shift-change-grid',
    'dataProvider'=>$model->reportingSearch(),
    'filter'=>$model,
	'enableSorting' => false,
    'columns'=>array(
		array(
			'name'=>'requesting_user',
			'header'=>'Requestor',
			'filter'=>CHtml::listData(User::model()->findAll(array('order'=>'username ASC','condition'=>'team =' . $model->team_id)),
																		 'iduser',
																		 'username'
																		 ),	
			'value'=>'$data->requestingUser_relation->username',
			'htmlOptions' => array(
								'style' => 'width:80px; text-align:center;',
							 ),
		),			
		array(
			'name'=>'current_shift',
			'header'=>'Requestor\'s Shift',
			'filter'=>CHtml::listData(Shift::model()->findAll(array('order'=>'start_time ASC','condition'=>'team_id =' . $model->team_id)),
																		 'idshift',
																		 'name'
																		 ),				
			'value'=>'($data->current_shift != null)? $data->getCurrentShift() : null',
			'htmlOptions' => array(
								'style' => 'width:80px; text-align:center;',
							 ),
		),		
		array(
			'name'=>'requested_shift',
			'header'=>'Requested Shift',
			'filter'=>CHtml::listData(Shift::model()->findAll(array('order'=>'start_time ASC','condition'=>'team_id =' . $model->team_id)),
																		 'idshift',
																		 'name'
																		 ),	
			'value'=>'$data->requestedShift_relation->name',
			'htmlOptions' => array(
								'style' => 'width:80px; text-align:center;',
							 ),
		),						
		array(
			'name'=>'requested_qshift',
			'header'=>'Requested QShift',
			'filter'=>CHtml::listData(QShift::model()->findAll(array('order'=>'start_time ASC','condition'=>'team_id =' . $model->team_id)),
																		 'idqshift',
																		 'name'
																		 ),	
			'value'=>'$data->requestedQshift_relation->name',
			'htmlOptions' => array(
								'style' => 'width:80px; text-align:center;',
							 ),
		),	
		array(
			'name'=>'day_requested',
			'header'=>'Date',
			'value'=>'$data->day_requested',
			'htmlOptions' => array(
								'style' => 'width:70px; text-align:center;',
							 ),
		),	
		array(
			'name'=>'target_user',
			'header'=>'Target User',
			'filter'=>CHtml::listData(User::model()->findAll(array('order'=>'username ASC','condition'=>'team=' . $model->team_id)),
																		 'iduser',
																		 'username'
																		 ),	
			'value'=> '$data->getTargetUser()', //'($data->targetUser_relation->username)',
			'htmlOptions' => array(
								'style' => 'width:80px; text-align:center;',
							 ),
		),	
		array(
			'name'=>'is_swap',
			'header'=>'Is Swap?',
			'value'=> 'User::getYesNoValue($data->is_swap)',
			'filter' => array('0'=>'No', '1'=>'Yes'),
			'htmlOptions' => array(
								'style' => 'width:20px;text-align:center;',
							 ),
		),		
		array(
			'name'=>'request_status',
			'header'=>'Status',
			'value'=> 'ShiftChange::getStatus($data->request_status)',
			'filter' => array('1'=>'Approved', '2'=>'Denied','3'=>'Pending','4'=>'Pending Cancel','5'=>'Cancelled'),
			'htmlOptions' => array(
								'style' => 'width:80px;text-align:center;',
							 ),
		),	
		array(
			'class'=>'CButtonColumn',
			'header'=>'Actions',
			'template'=>'{view}',
			'buttons'=>array(
						'view'=>array(
									'url'=>'Yii::app()->createUrl("shiftChange/view", array("id"=>$data->idshift_change))', 
									'label'=>'View Change',
									'options' => array('style'=>'width:10px;','title'=>'View Details','target'=>'_blank')
						          ),
					   ),			
		),	
        /*
        'idshift_change',
        'comments',
        'team_id',
        */
    ),
)); 

$this->renderExportGridButton($gridWidget,'Export to Excel',array('class'=>'btn btn-info pull-right'));
?>